package com.controller;

import com.pojo.Warehouse;
import com.service.WarehouseService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/base/warehouse")
public class WarehouseHandler {
    @Resource
    private WarehouseService warehouseService;

    /**
     * 查询单个
     * @param warehouseCode
     * @return Warehouse
     */
    @RequestMapping("/getWarehouse")
    public Warehouse getWarehouse(String  warehouseCode){
        return warehouseService.get(warehouseCode);
    }


    /**
     * 查询单个
     * @return Warehouse
     */
    @RequestMapping("/getWarehouseCode")
    public Warehouse getWarehouseCode(){
        return warehouseService.getCode();
    }

    /**
     * 删除单个
     * @param id
     * @return int
     */
    @RequestMapping("/delWarehouse")
    public String deleteWarehouse(Integer id){
        String msg="删除失败！";
        int i =warehouseService.del(id);
        if(i>0){
            msg="删除成功！";
        }
        return msg;
    }

    /**
     * 修改
     * @param warehouse
     * @return
     */
    @RequestMapping("/updateWarehouse")
    public String updateWarehouse(Warehouse warehouse){
        String msg="修改失败！";
        int i = warehouseService.update(warehouse);
        if(i>0){
            msg="修改成功！";
        }
        return msg;
    }

    /**
     * 添加
     * @param warehouse
     * @return
     */
    @RequestMapping("/addWarehouse")
    public String addWarehouse(Warehouse warehouse){

        String msg="添加失败！";
        int i = warehouseService.add(warehouse);
        if(i>0){
            msg="添加成功！";
        }
        return msg;
    }


}
